package com.vitas.coin.resp

import android.util.Log
import com.snap.common.bean.resp.RespBean
import com.snap.http.HttpUtil
import com.snap.http.request.addParam
import com.snap.http.request.asResponse
import com.snap.util.AesEncryptUtil
import com.snap.util.GsonUtil
import com.vitas.coin.constant.HttpConstant
import com.vitas.coin.data.bean.VoiceCateRecommendBean
import com.vitas.coin.data.bean.VoiceListBean
import com.vitas.coin.ui.dialog.LoadingDialog

/**
 * @description:
 * @author: Funky
 * @date: 2024/10/21 13:02
 */
class HomeResp {

    suspend fun requestCateRecommendList(action: (VoiceCateRecommendBean?) -> Unit) {
        HttpUtil.get(HttpConstant.VOICE_CATE)
            .addParam("type", 2) // 1-儿歌；2-手机铃声
            .asResponse<RespBean<String>>()
            .onSuccess {
                Log.e("tagg", "request tabs success")
                if (it.isSuccess()) {
                    val data = AesEncryptUtil.decrypt(it.data)
                    val bean = GsonUtil.fromJson(data, VoiceCateRecommendBean::class.java)
                    action.invoke(bean)
                }
            }
            .onFailure {
                Log.e("tagg", "request fail")
                action.invoke(null)
            }
    }



    suspend fun requestVoiceList(parentId: Long,
                                 pageNum: Int = 1,
                                 pageSize: Int = 10,
                                 action: (VoiceListBean?) -> Unit) {
        HttpUtil.get(HttpConstant.VOICE_LIST)
            .addParam("parentId", parentId)
            .addParam("pageNum", pageNum)
            .addParam("pageSize", pageSize)
            .asResponse<RespBean<String>>()
            .onSuccess {
                if (it.isSuccess()) {
                    val data = AesEncryptUtil.decrypt(it.data)
                    val bean = GsonUtil.fromJson(data, VoiceListBean::class.java)
                    action.invoke(bean)
                }
            }
            .onFailure {
                action.invoke(null)
            }
    }
}